<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" width="85%" destroy-on-close @closed="$emit('closed')" align-center>
        <el-container>
            <el-container>
                <el-header>
                    <div class="left-panel">
                        <!-- <el-button type="primary" @click="back">确定</el-button> -->
                        <!-- <el-button type="primary" icon="el-icon-plus" v-auth="'goods.add'" @click="add">新增</el-button> -->
                    </div>
                    <div class="right-panel">
                        <div class="right-panel-search">
                            <el-input v-model="search.contract_code" placeholder="请输入销售编码" clearable @keyup.enter="upsearch"></el-input>
                            <el-input v-model="search.customer_name" placeholder="请输入客户名称" clearable @keyup.enter="upsearch"></el-input>
                            <el-select v-model="search.status" filterable placeholder="审核状态">
                                <el-option label="待审核" :value="0" />
                                <el-option label="审核通过" :value="1" />
                                <el-option label="审核驳回" :value="2" />
                            </el-select>
                            <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                            <el-button type="primary" icon="el-icon-refresh" @click="refresh"></el-button>
                        </div>
                    </div>
                </el-header>
                <el-main class="nopadding">
                    <scTable ref="table" row-key="id" :apiObj="apiObj" highlight-current-row @row-click="selectionChange" stripe remoteSort remoteFilter border height="650" :params="query">
                        <!-- <el-table-column type="selection" width="50" reserve-selection align="center"></el-table-column> -->
                        <el-table-column width="1"></el-table-column>
                        <el-table-column type="index" label="序号" align="center" width="50"></el-table-column>
                        <el-table-column label="销售单号" prop="contract_code" align="center"></el-table-column>
                        <el-table-column label="客户" prop="customer.customer_name" align="center"></el-table-column>
                        <el-table-column label="备注" prop="remark" align="center">
                            <template #default="scope">
                                <el-popover placement="top-start" :width="200" trigger="hover" :content="scope.row.remark">
                                    <template #reference>
                                        <el-button style="padding: 5px 0;font-size: 12px" text class="m-2">{{ scope.row.remark.substring(0, 10) }}</el-button>
                                    </template>
                                </el-popover>
                            </template>
                        </el-table-column>
                        <el-table-column label="开单日期" prop="open_single" align="center"></el-table-column>
                        <el-table-column label="销售交期" prop="deliver_date" align="center"></el-table-column>
                        <el-table-column label="销售金额" prop="contract_price" align="center" width="85"></el-table-column>
                        <el-table-column label="累计收款" prop="pay_price" align="center" width="85"></el-table-column>
                    </scTable>
                </el-main>
            </el-container>
        </el-container>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
		</template>
        <save-add v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-add>
	</el-dialog>
</template>

<script>
import saveAdd from './save.vue'
export default {
    props:{
        query: { type: Object, default: () => ({}) },
    },
    components: { saveAdd },
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '选择销售',
				edit: '编辑销售',
				show: '查看'
			},
			visible: false,
			isSaveing: false,
			apiObj: this.$API.contract.contract.list,
			selection: [],
			search: {
				contract_code: null,
                customer_name:null,
                status:null,
                contract_status:null,
			},
            dialog: {
				save: false,
			},
		}
	},
	mounted() {
	},
	methods: {
		// 显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
        // 选择事件
        selectionChange(selection) {
            this.$emit('success', selection)
            this.visible = false;
		},
        // 选中返回
        back(){
            this.$emit('success', this.selection,this.type)
            this.visible = false;
        },
        //销售新增
		add() {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('add')
			})
		},
        // 更新销售新增
        handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			}
		},
        //搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
        refresh(){
            for (const key in this.search) {
                this.search[key] = null;
            }
            this.$refs.table.upData(this.search)
        },
	}
}
</script>

<style></style>
